package com.shaoshaohuo.app.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.SupplyRecord;
import com.shaoshaohuo.app.utils.AreaUtil;
import com.shaoshaohuo.app.utils.ImageLoadUtil;
import com.shaoshaohuo.app.utils.StringHelper;

import java.util.List;

public class DumpGoodsGridAdapter<T> extends MyBaseAdapter<SupplyRecord> {

	public DumpGoodsGridAdapter(Context ctx, List<SupplyRecord> list, boolean flag) {
		super(ctx, list, flag);
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup group) {
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.view_dump_goods_grid_item, null);
		}
		ViewHolder holder = ViewHolder.getHolder(convertView);

		SupplyRecord item = list.get(pos);

		holder.titleText.setText(item.getmName());
		holder.subtitleText.setText(item.getcName());
		holder.priceText.setText(item.getMoney());
		holder.tv_description.setText(item.getContent());
		if(item.getSmall_images()!=null&&item.getSmall_images().size()>0){
			ImageLoader.getInstance().displayImage(item.getSmall_images().get(0), holder.picture,
					ImageLoadUtil.getDisplayImageOptions(R.drawable.icon_vegetable_no_ad));
		}else{
			holder.picture.setImageResource(R.drawable.icon_vegetable_no_ad);
		}
		/*holder.addressImage.setText(AreaUtil.getAreaFullname(item.getCityid()) + item.getAddress());
		holder.timeText.setText(StringHelper.formatDateMinute(item.getCdate()));
		holder.browserNum.setText((item.getVnum() == null ? 0 : item.getVnum()) + "人浏览");*/
		/*

		String moneyType = item.getMoneyType();
		if ("origin".equals(moneyType)) {
			holder.iv_price_changdi.setVisibility(View.VISIBLE);
			holder.iv_price_shichang.setVisibility(View.GONE);
		}else if ("market".equals(moneyType)) {
			holder.iv_price_changdi.setVisibility(View.GONE);
			holder.iv_price_shichang.setVisibility(View.VISIBLE);
		}else{
			holder.iv_price_changdi.setVisibility(View.GONE);
			holder.iv_price_shichang.setVisibility(View.GONE);
		}*/
		holder.priceUnitText.setText("/" + item.getUnit());
		/*if ("1".equals(item.getShuai())) {
			holder.shuaiImage.setVisibility(View.VISIBLE);
		} else {
			holder.shuaiImage.setVisibility(View.GONE);
		}*/

		return convertView;
	}

	static class ViewHolder {
		TextView titleText;
		TextView subtitleText;
		TextView priceText;
		TextView priceUnitText;
		TextView tv_description;
		// ImageView imageFlagImage;
//		ImageView shuaiImage;
//		TextView addressImage;
//		TextView timeText;
//		TextView browserNum;
		ImageView picture;

//		ImageView iv_price_changdi;// 1.8
//		ImageView iv_price_shichang;

		public ViewHolder(View convertView) {
			titleText = (TextView) convertView.findViewById(R.id.textview_name);
			subtitleText = (TextView) convertView.findViewById(R.id.textview_catname);
			priceText = (TextView) convertView.findViewById(R.id.textview_price);
			priceUnitText = (TextView) convertView.findViewById(R.id.textview_price_unit);
			tv_description = (TextView) convertView.findViewById(R.id.tv_description);
			picture = (ImageView) convertView.findViewById(R.id.iv_picture);
			/*addressImage = (TextView) convertView.findViewById(R.id.textview_address);
			timeText = (TextView) convertView.findViewById(R.id.textview_time);
			// holder.imageFlagImage = (ImageView)
			// convertView.findViewById(R.id.imageview_have_image);
			shuaiImage = (ImageView) convertView.findViewById(R.id.imageview_shuai);
			browserNum = (TextView) convertView.findViewById(R.id.tv_browser);

			iv_price_changdi = (ImageView) convertView.findViewById(R.id.iv_price_changdi);
			iv_price_shichang = (ImageView) convertView.findViewById(R.id.iv_price_shichang);
*/
			convertView.setTag(this);
		}

		public static ViewHolder getHolder(View convertView) {
			return (ViewHolder) (convertView.getTag() != null ? convertView.getTag() : new ViewHolder(convertView));
		}
	}

}
